<template>
  <div>
    <!--面包屑导航区域-->
    <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 20px;overflow: hidden">
      <el-breadcrumb-item :to="{ path: '/admin/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>日志管理</el-breadcrumb-item>
      <el-breadcrumb-item>登录日志</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card >

      <div class="title">
        <template>
          <p>登录日志</p>
        </template>
        <el-input
            style="width: 20%;float: right;margin-bottom: 20px"
            placeholder="请输入内容"
            clearable
        >
          <el-button
              slot="append"
              icon="el-icon-search"
          ></el-button>
        </el-input>
      </div>


      <el-table :data="tableData"
                border stripe style="width: 90%; margin-top:20px;
    margin-bottom: 20px">
        <el-table-column align="center" label="id" prop="id">
        </el-table-column>

        <el-table-column align="center" label="用户ID" prop="userId">
        </el-table-column>

        <el-table-column align="center" label="登录IP" prop="ip">
        </el-table-column>

        <el-table-column align="center" label="昵称" prop="username">
        </el-table-column>

        <el-table-column prop="userAgent" label="浏览器内核" align="center"
                         :show-overflow-tooltip="true">
        </el-table-column>

        <el-table-column align="center" label="登录时间" prop="createTime">
        </el-table-column>

        <!--        <el-table-column align="center" label="修改时间" prop="updateTime">-->
        <!--        </el-table-column>-->

      </el-table>

      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :hide-on-single-page="true"
          :page-size="pageSize"
          layout="total, prev, pager, next,jumper"
          :total="total"
          background
      ></el-pagination>

    </el-card>
  </div>
</template>

<script>
import BaseUrl from "@/http/request/BaseUrl";
import TokenAxios from "@/http/request/TokenAxios";

export default {
  data() {
    return {
      // 当前每页显示多少条数据
      pageSize: 10,
      //分页相关数据
      currentPage: this.$router.currentRoute.query.page ? parseInt(this.$router.currentRoute.query.page) : 1,
      tableData: [],
      total: 0,
    }
  },
  methods: {
    //切换分页
    handleCurrentChange(page) {
      this.$router.replace('?page=' + page);
      this.loadUserList();
    },
    loadUserList() {
      let page = this.$router.currentRoute.query.page;
      if (!page) {
        page = 1;
      }

      let url = BaseUrl.ADMIN_ACCOUNT + '/admin/LoginLog?page=' + page;
      console.log('url=' + url);

      TokenAxios.get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          console.log(this.tableData)
          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          this.total = jsonResult.data.total;
        } else {
          let title = '操作失败';
          this.$alert(jsonResult.message, title, {
            confirmButtonText: '确定',
            callback: action => {
            }
          })
        }
      })
    }
  },
  mounted() {
    this.loadUserList();
  }

}
</script>

<style scoped>
.pagination-container {
  float: right;
  margin-top: 1.25rem;
  margin-bottom: 1.25rem;
}

.box-card {
  width: 98%;
  margin: 1%;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.clearfix span {
  font-weight: 600;
}
</style>